package com.example.workoutjournal;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class DisplayExercise extends Activity {

	private DAO database;
	private Integer exID;
	private String setID;
	private String exName;
	private String setName;
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_display_exercise);
		getActionBar().hide();
		database = new DAO(this);
		database.open();
		
		Intent intent = getIntent();
	    String message = intent.getStringExtra(SetActivity.EX_ID);
	    String exName = intent.getStringExtra("EX_NAME");
	    String setID = intent.getStringExtra("SET_ID");
	    String setName = intent.getStringExtra("SET_NAME");
	    this.setName = setName;
	    this.setID = setID;
	    this.exName = exName;
	    
	    setTitle(exName);
	    this.exID = Integer.valueOf(message);
	    // Create the text view
	    Exercise exercise = database.getExercise(Integer.valueOf(message));
	    
	    
	    TextView textView = (TextView) findViewById(R.id.exercise);
	    textView.setTextSize(40);
	    textView.setText(exercise.showInfo());

	    // Set the text view as the activity layout
	  //  setContentView(textView);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.display_exercise, menu);
		return true;
	}
	
	public void deleteEx(View view){
		database.deleteExercise(this.exID);
		Intent intent = new Intent(this, SetActivity.class);
		intent.putExtra("TOAST_TEXT", "Exercise "+exName+" deleted successfully");
		intent.putExtra("SET_NAME", setName);
		intent.putExtra(MyExercises.SET_ID, setID);
		database.close();
		startActivity(intent);
		
	}

}
